<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/2/23
 * Time: 10:37
 */

namespace app\common\helpers;


use think\Request;

class ImageUtil
{
    /**
     * @param string $url
     * @return array
     * 单图  后端
     */
    public static function handle($url = "")
    {


        $preg = "/^http(s)?:\\/\\/.+/";
        if ($url && !preg_match($preg, $url) ) {
            return  Request::instance()->domain() . $url;
        } else {
            return $url && ($url != "[]") ? $url : "";

        }
    }


    /**
     * @param string $url
     * @return array
     * 多图  后端
     */
    public static function handleMore($url)
    {
        $arr = [];
        $preg = "/^http(s)?:\\/\\/.+/";
        if ($url && !preg_match($preg, $url) && ($url != "[]")) {
            $url_list = explode(',',$url);
            if($url_list){
                foreach ($url_list as $v) {
                    $arr[] = Request::instance()->domain() . $v;
                }
            }
        }
        return $arr;
    }

}